import { _decorator, Button, size, Sprite, UITransform } from 'cc';
import { $planet_BasePop_poof$ } from '../../../frame/component/ui.pop';
import { $planet_ClientAPI_poof$ } from '../api/client.api';
import $planet_Config_poof$ from '../manager/config.dynamic';
import $planet_GameAssets_poof$ from '../manager/game-assets';
import type { $planet_Pop_poof$ } from '../ui/pop';
const { ccclass, property } = _decorator;

@ccclass('$planet_Setting_poof$')
export class $planet_Setting_poof$ extends $planet_BasePop_poof$<typeof $planet_Pop_poof$, null> {
	protected $planet_default_return_poof$: null;

	private $planet_ui_background_poof$: UITransform;

	protected $planet_initAfterOnLoad_poof$(){
		this.$planet_ui_background_poof$ = this.node.getChildByName('background').getComponent(UITransform);
		this.$planet_renderLocalUI_poof$();
	}

	public $planet_onShow_poof$(): void {
		$planet_BasePop_poof$.$planet_jelly_enter_poof$(this.$planet_ui_background_poof$.node);
	}

	protected $planet__click_event__poof$: { [name: string]: (this: $planet_Setting_poof$, button: Button) => void; } = {
		agreement(btn){
			btn.interactable = false;
			$planet_ClientAPI_poof$.$planet_Link_poof$($planet_Config_poof$.$planet_otherConfig_poof$.$planet_agreement_poof$);
		},
		privacy(btn){
			btn.interactable = false;
			$planet_ClientAPI_poof$.$planet_Link_poof$($planet_Config_poof$.$planet_otherConfig_poof$.$planet_privacy_poof$);
		},
		close(btn){
			btn.interactable = false;
			$planet_BasePop_poof$.$planet_jelly_leave_poof$(this.$planet_ui_background_poof$.node).then(()=>{
				this.$planet_close_poof$(null);
				btn.interactable = true;
			});
		}
	}

	private $planet_renderLocalUI_poof$(){
		(<const>[
			['agreement', 0],
			['privacy', 1],
		]).forEach(([name, ti])=>{
			let ui = this.$planet___btn_map___poof$.get(name).getComponent(UITransform);
			let sframe = $planet_GameAssets_poof$.$planet_getLangTexture_poof$(ti);
			let [R, r] = [ui.contentSize, sframe.originalSize].map(n=>n.width/n.height);

			if(r > R){
				let sprite = ui.node.getChildByName('word').getComponent(Sprite);
				sprite.spriteFrame = sframe;
				let ratio = abd.$planet_size_poof$.$planet_innerRatio_poof$(sframe.originalSize, ui.contentSize) * 0.8;
				sprite.getComponent(UITransform).setContentSize(sframe.originalSize.width * ratio, sframe.originalSize.height * ratio);
			}else abd.$planet_cc_poof$.$planet_skinPeeler_poof$(ui.node.getChildByName('word'), sframe, {height: true});
		});

		let ui_title = this.$planet_ui_background_poof$.node.getChildByName('title-word').getComponent(UITransform);
		let sframe_title = $planet_GameAssets_poof$.$planet_getLangTexture_poof$(11);
		let R = this.$planet_ui_background_poof$.width / ui_title.height;
		let r = sframe_title.originalSize.width / sframe_title.originalSize.height;

		if(r > R){
			let ratio = abd.$planet_size_poof$.$planet_innerRatio_poof$(sframe_title.originalSize, size(this.$planet_ui_background_poof$.width, ui_title.height)) * 0.8;
			ui_title.getComponent(Sprite).spriteFrame = sframe_title;
			ui_title.setContentSize(sframe_title.originalSize.width * ratio, sframe_title.originalSize.height * ratio);
		}else abd.$planet_cc_poof$.$planet_skinPeeler_poof$(ui_title.node, sframe_title, {height: true});
	}
}

